package com.czq.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * @author Administrator
 * @date 2022/2/27 0027 23:07
 */
public class CustomValidConstraintValidator implements ConstraintValidator<CustomValid,String> {

    private Set<Integer> values = new HashSet<>();

    @Override
    public void initialize(CustomValid constraintAnnotation) {
        int[] value = constraintAnnotation.value();
        for (int v : value){
            values.add(v);
        }
    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        return values.contains(Integer.valueOf(value));
    }
}
